<?php

/**
 * @return \Illuminate\Auth\GenericUser|\Illuminate\Database\Eloquent\Model|\App\Models\User
 * @author thanatos thanatos915@163.com
 */
function get_user()
{
    return app(\Dingo\Api\Auth\Auth::class)->user();
}

function get_user_id()
{
    return get_user() ? get_user()->id : 0;
}


/**
 * @param mixed ...$str
 * @throws Exception
 * @author thanatos thanatos915@163.com
 */
function can(...$str)
{
    $user = get_user();
    if (!$user->hasRole("超级管理员") && !$user->hasAnyPermission($str)) {
        throw new \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException("无访问权限");
    }
}

/**
 * 判断是否是超级管理员
 * @return bool
 * @author thanatos thanatos915@163.com
 */
function isAdmin()
{
    return get_user()->hasRole("超级管理员");
}
